package com.wky.org.controller;

import com.wky.basic.Result.JsonResult;
import com.wky.org.pojo.Employee;
import com.wky.org.service.EmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 员工管理
 */

@RestController
@RequestMapping("/org/emp")
@CrossOrigin
public class EmployeeController {
    @Autowired
    private EmployeeService employeeService;

    /**
     * 查询所有员工
     * @return
     */
    @GetMapping("/findAll")
    public JsonResult findAll(){
        return JsonResult.success(employeeService.findAll());
    }

    /**
     *  根据id查询员工
     */
    @GetMapping("/findById")
    public JsonResult findById(Long id){
        return JsonResult.success(employeeService.findById(id));
    }

    /**
     * 分页查询员工
     */
    @PostMapping("/findByPage")
    public JsonResult findByPage(@RequestBody Employee employee){
        return JsonResult.success(employeeService.findByPage(employee));
    }

    /**
     * 添加员工
     */
    @PostMapping("/add")
    public JsonResult add(@RequestBody Employee employee){
        employeeService.add(employee);
        return JsonResult.success();
    }

    /**
     * 修改员工
     */
    @PostMapping("/update")
    public JsonResult update(@RequestBody Employee employee){
        employeeService.update(employee);
        return JsonResult.success();
    }

    /**
     * 删除员工
     */
    @DeleteMapping("/deleteById")
    public JsonResult delete(Long id){
        employeeService.delete(id);
        return JsonResult.success();
    }

    /**
     * 批量删除员工
     */
    @DeleteMapping("/deleteByIds")
    public JsonResult deleteBatch(@RequestBody Long[] ids){
        for (Long id : ids) {
            employeeService.delete(id);
        }
        return JsonResult.success();
    }

}
